<template>
    <LDrawerForm 
        :visible="visible"  
        :confirmLoading="confirmLoading" 
        :title="title" ref="menuForm" 
        :formAttributes="formAttributes"
        @handleOk="handleOk" 
        @handleCancel="handleCancel"
        @clickEventHandler="clickEventHandler"
        @changeEventHandler="changeEventHandler">
    </LDrawerForm>

</template>

<script>
import LDrawerForm from '@/components/lt/form/LDrawerForm'
import pick from 'lodash.pick'
import request from '@/utils/request'
import defaultSettings from '@/config/defaultSettings'

export default {
    name:'menuForm',
    components:{
        LDrawerForm
    },
    mixins:[],
    data(){
        return{
            title:'详情',
            visible:false,
            confirmLoading: false,
            model:{},
            defaultSettings,
            formAttributes:{
              type:'',//collapse,tabs
              formItems:[
                {
                  title:'标签一',
                  columns:1,
                  fields:[
                    {field:'systemNo',label:'模块',component:'input',disabled:true,rules: [{ required: true, message: '请输入模块信息!' }]},
                    {field:'parentId',label:'父菜单',component:'treeSelect',dictCode:defaultSettings.数据字典.某个系统下的菜单下拉树},
                    {field:'menuTitle',label:'标题',component:'input',rules: [{required: true, message: '请输入标题!'}]},
                    {field:'menuPath',label:'路径',component:'input'},
                    {field:'menuComponent',label:'组件',component:'input'},
                    {field:'sortNo',label:'排序',component:'inputNumber'},
                    {field:'menuIcon',label:'图标',component:'iconSelect'},
                    {field:'isUse',label:'是否可用',component:'select',rules: [{ required: true, message: '请选择是否隐藏!' }],dictCode:defaultSettings.数据字典.是否,initialValue:'1'},
                    {field:'menuDesc',label:'描述',component:'input'},
                    {field:'pageId',label:'自定义页面内码',component:'input'},
                    {field:'extLink',label:'外部链接地址',component:'input'},
                    {field:'isNewWin',label:'是否打开新窗口',component:'select',dictCode:defaultSettings.数据字典.是否,rules: [{required: true, message: '是否可用不能为空'}],initialValue:'0'},
                  ]
                },
              ]

            },
          

            
        }
            
        
    },
    methods:{
        add () {
            this.edit({});
        },
        edit (record) {
            this.visible = true;
            this.model = Object.assign({}, record);
            this.formAttributes.formItems[0].fields[1].dictParam=this.model.systemNo
            this.$nextTick(() => {
                this.$refs.menuForm.getForm().setFieldsValue(pick(this.model,'parentId','menuTitle','menuPath','menuComponent','sortNo','menuIcon','isUse','menuDesc','systemNo','pageId','extLink','isNewWin'))
            })
        },
        handleOk(){
            const that = this;
            this.$refs.menuForm.getForm().validateFields((err, values) => {
                if (!err) {
                    that.confirmLoading = true
                    let formData = Object.assign(this.model, values);
                    request({url: '/SysMenuController/save',method: 'post',data: formData}).then((res)=>{
                        if(res.success){
                            that.close()
                            that.$message.success(res.message);
                        }else{
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                    //    that.close()
                    })
                    
                }
            })
        },
        handleCancel(){
            this.visible=false
        },
        close () {
            this.$emit('close');
            this.visible = false;
        },
         /**
         * 表单内容发生变化
         */
        changeEventHandler(changeItem){
     
        },
        clickEventHandler(field,form){
            
        }

    }
}
</script>